﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MipsPipelineSimulator
{
    public partial class CommandForm : Form
    {
        public MainForm parentMainForm;

        public bool isTouchedWithParent = true;

        public CodeControl codeControl = null;

        public RegisterControl registerControl = null;

        public MemoryControl memoryControl;

        public CommandForm(MainForm parentMainForm)
        {
            this.parentMainForm = parentMainForm;
            InitializeComponent();

            this.SetPosition();
            codeControl = new CodeControl(this.parentMainForm);
           
            codeTag.Controls.Add(codeControl);
            registerControl = new RegisterControl();
           
            registerTag.Controls.Add(registerControl);
            memoryControl = new MemoryControl();
            
            memoryTag.Controls.Add(memoryControl);
        }

        public CodeControl CodeControl
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        public MemoryControl MemoryControl
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        public RegisterControl RegisterControl
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        private void CommandForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
        }

        private void CommandForm_Load(object sender, EventArgs e)
        {
            codeControl.Location = new Point(0, 0);
            codeControl.Height = this.Height - 40;

            registerControl.Location = new Point(0, 0);
            registerControl.Height = this.Height - 56;

            memoryControl.Location = new Point(0, 0);
            memoryControl.Height = this.Height - 56;
        }

        public void SetPosition()
        {
            Rectangle parentPosition = parentMainForm.DesktopBounds;
            this.SetDesktopLocation(parentPosition.Right, parentPosition.Top);
        }

        public bool JudgeIfToTouch()
        {
            Rectangle parentPosition = parentMainForm.DesktopBounds;
            Rectangle childPosition = this.DesktopBounds;
            if (Math.Abs(childPosition.Left - parentPosition.Right) < 20 && Math.Abs(childPosition.Top - parentPosition.Top) < 20)
            {
                return true;
            }
            return false;
        }

        private void CommandForm_Move(object sender, EventArgs e)
        {
            if (JudgeIfToTouch())
            {
                this.isTouchedWithParent = true;
                this.SetPosition();
            }
            else
            {
                this.isTouchedWithParent = false;
            }
        }
    }
}
